<template>
  <Form
    name="dictForm"
    ref="formDict"
    :labelCol="labelCol"
    :wrapperCol="wrapperCol"
    @finish="onToolFinish"
    :initialValues="currentForm"
  >
    <Card style="width: 100%">
      <Row>
        <Col>
          <FormItem name="resourceNumber" label="资源编号" :rules="dictNameRules">
            <Input placeholder="请输入资源编号" style="width: 100%" disabled/>
          </FormItem>
        </Col>
      </Row>
      <Row>
        <Col>
          <FormItem name="resourceName" label="资源名称" :rules="dictTypeRules">
            <Input placeholder="请输入资源名称" style="width: 100%" allowClear/>
          </FormItem>
        </Col>
      </Row>
           <Row>
        <Col>
          <FormItem name="resourceType" label="资源类型" :rules="dictTypeRules">
            <Select placeholder="资源类型" style="width: 100%" allowClear>
              <Option
                v-for="dict in dict.type.resource_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
              ></Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row>
        <Col>
          <FormItem name="fatoryName" label="厂家名称">
             <Input placeholder="请输入厂家名称" style="width: 100%" allowClear/>
          </FormItem>
        </Col>
      </Row>
           <Row>
        <Col>
          <FormItem name="ipAddress" label="iP地址">
            <Input placeholder="请输入iP地址" style="width: 100%" allowClear/>
          </FormItem>
        </Col>
      </Row>
          <Row>
        <Col>
          <FormItem name="address" label="是否使用中">
            <TextArea placeholder="是否使用中" style="width: 100%" allowClear />
          </FormItem>
        </Col>
      </Row>
        <Row>
        <Col>
          <FormItem name="remark" label="备注">
            <TextArea placeholder="备注" style="width: 100%" allowClear />
          </FormItem>
        </Col>
      </Row>
      <Row>
        <Col :span="24">
          <FormItem :wrapperCol="{ span: 24 }" style="text-align: center">
            <Button
              type="primary"
              size="md"
              style="width: 100px"
              @click="sumbitForm"
              >提交</Button
            >
            <Button
              style="margin-left: 20px; width: 100px"
              size="md"
              @click="handleCancel"
              >取消</Button
            >
          </FormItem>
        </Col>
      </Row>
    </Card>
  </Form>
</template>

<script>
import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
import { Message } from "@uni/vue";
export default {
  dicts: ['resource_type'],
  props: {
    id: {
      default: "",
    },
    currentRow: {
      default: () => {},
    },
  },
  data() {
    return {
      labelCol: {
        span: 3,
      },
      wrapperCol: {
        span: 20,
      },
      currentForm: {
        resourceNumber: this.currentRow.resourceNumber,
        resourceName: this.currentRow.resourceName,
        resourceType: this.currentRow.resourceType,
        status: this.currentRow.status == "0" ? "0" : "1",
        fatoryName: this.currentRow.fatoryName,
        ipAddress: this.currentRow.ipAddress,
        address:  this.currentRow.address,
        remark:  this.currentRow.remark,
      },
      dictNameRules: [{ required: true, message: "请输入字典名称" }],
      dictTypeRules: [{ required: true, message: "字典类型不能为空" }],
      roleOptions: [],
    };
  },
  methods: {
    handleCancel() {
      this.$emit("handleCancel");
    },
    sumbitForm() {
      this.$refs.formDict.submit();
    },
    onToolFinish(formData) {
      formData.status = formData.status === "0" ? "0" : "1";
      if (this.id) {
        formData.dictId = this.id;
        updateType(formData).then((response) => {
          if (response.code == 200) {
            Message.success({ text: "修改成功" });
            this.$emit("handleCancel");
          } else {
            Message.error({ text: "修改失败" });
          }
        });
      } else {
        addType(formData).then((response) => {
          if (response.code == 200) {
            Message.success({ text: "新增成功" });
            this.$emit("handleCancel");
          } else {
            Message.error({ text: "新增失败" });
          }
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .uni-modal-body {
  padding: 0;
}
::v-deep .uni-modal-footer {
  display: none;
}
::v-deep .uni-card-title {
  display: none;
}
</style>